package com.sq.goodline.controller.dto;

import java.io.Serializable;

import com.fasterxml.jackson.annotation.JsonInclude;

@JsonInclude(JsonInclude.Include.NON_NULL)
public class TransResponse<T> implements Serializable  {
	private static final long serialVersionUID = 1L;
	//"状态码, 0为成功，其它失败")
	private String errorCode;
	//"失败描述")
	private String errorMessage;
	//"业务对象")
	private T responseBody;

	public static boolean isSuccess(TransResponse transResponse){
		return "0".equals(transResponse.getErrorCode()) ? true : false;
	}

	public static <T> TransResponse<T> success() {
        return new TransResponse("0", "success");
    }
	public static <T> TransResponse<T> success(T data) {
		return new TransResponse("0", "success", data);
	}
	public static <T> TransResponse<T> error(String message) {
		return new TransResponse("99", message);
	}
	public static <T> TransResponse<T> error(String code,String message) {
		return new TransResponse(code, message);
	}
	public static <T> TransResponse<T> error(String code,String message,T data) {
        return new TransResponse(code, message, data);
    }
	
	public TransResponse(){
	}
	
	public TransResponse(String errorCode, String errorMessage){
		this.setErrorCode(errorCode);
		this.setErrorMessage(errorMessage);
	}
	public TransResponse(String errorCode, String errorMessage,T data){
		this.setErrorCode(errorCode);
		this.setErrorMessage(errorMessage);
		this.setResponseBody(data);
	}
	
	public String getErrorCode() {
		return errorCode;
	}
	public void setErrorCode(String errorCode) {
		this.errorCode = errorCode;
	}
	public String getErrorMessage() {
		return errorMessage;
	}
	public void setErrorMessage(String errorMessage) {
		this.errorMessage = errorMessage;
	}
	public T getResponseBody() {
		return responseBody;
	}
	public void setResponseBody(T responseBody) {
		this.responseBody = responseBody;
	}
	
}
